package com.zhibang.util;

import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 统一json返回类
 *注意：转json的类必须具有无参构造和get/set
 */
@Data
@NoArgsConstructor //无参构造
public class Result<T> {
    private Integer code;//响应状态码
    private  String msg; //响应消息
    private T data; //响应数据

    public Result(int code, String msg){
        this.code=code;
        this.msg=msg;
    }
    public Result(int code, String msg, T data){
        this.code=code;
        this.msg=msg;
        this.data=data;
    }
    public static <T>Result<T>ok(String msg){
        return new Result<>(200,msg);
    }
    public static <T>Result<T>ok(String msg,T data){
        return new Result<>(200,msg,data);
    }
    public static <T>Result<T>data(T data){
        return new Result<>(200,"success",data);
    }

    public static <T>Result<T>fail(int code ,String msg){
        return new Result<>(code,msg);
    }

    public static <T>Result<T>fail(String msg){
        return new Result<>(500,msg);
    }
}
